package windowFactoryPackage;

import java.awt.event.*;
import javax.swing.*;

public class ViewButton extends JButton {
	Query q = new Query();
	
	public ViewButton() {
		super("View Details");
		this.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				
				for (int i = 0; i < ResultsPanel.vbArrayList.size(); i++) {
					if (e.getSource() == ResultsPanel.vbArrayList.get(i)) {

						// makes sure user is logged in to proceed
						if (tester.UserIsLoggedIn) {
							System.out.println("ViewButton pressed at position " + i);
							
							Query.program_id = Query.progId.get(i);
							Query.sourceCode_idSearch = Query.sourceCodeId.get(i);
							Query.ip_id = Query.ipId.get(i);
							q.detailedProgram();
							System.out.println("Source code id: " + Query.sourceCode_idSearch);
							System.out.println("Prog id: " + Query.program_id);
							
							WindowGenerator.generateInformationWindowFromCustom(i);
						} else
							JOptionPane.showMessageDialog(null,
									"You must login to download this program.");

					}
				}
				System.out.println("view button prog id: " + Query.program_id);
				
			}
		});
	}
}
